package me.winds.infrared.module.basic.bean;

import android.graphics.Bitmap;

import java.util.Arrays;

import me.winds.infrared.AppConfig;

/**
 * Author:  winds
 * Data:    2018/8/27
 * Version: 1.0
 * Desc:
 */


public class IrBean {
    public boolean ready;
    public Bitmap bitmap;
    public double maxTemp;
    public double centerTemp;

    public IrBean() {
        ready = false;
    }

    public IrBean(Bitmap bitmap, double[] arr) {
        ready = true;
        this.bitmap = bitmap;
        this.maxTemp = getMaxTemperature(arr);
        this.centerTemp = getCenterTemperature(arr);
    }


    public void setData(int[] imageBuffer, double[] tempBuffer) {
        ready = true;
        this.bitmap = Bitmap.createBitmap(AppConfig.SIZE_WIDTH, AppConfig.SIZE_HEIGHT, Bitmap.Config.ARGB_8888);
        bitmap.setPixels(imageBuffer, 0, AppConfig.SIZE_WIDTH, 0, 0, AppConfig.SIZE_WIDTH, AppConfig.SIZE_HEIGHT);
        this.maxTemp = getMaxTemperature(tempBuffer);
        this.centerTemp = getCenterTemperature(tempBuffer);
    }

    /**
     * 取集合最大值
     *
     * @param arr
     * @return
     */
    public double getMaxTemperature(double[] arr) {
        Arrays.sort(arr);
        return arr[arr.length - 1];
    }


    /**
     * 获取中心点温度
     *
     * @param arr
     * @return
     */
    public double getCenterTemperature(double[] arr) {
        return arr[AppConfig.SIZE_WIDTH * (AppConfig.SIZE_HEIGHT / 2) + (AppConfig.SIZE_WIDTH / 2)];
    }
}
